<?php global $has_permit; ?>
<div class="db_left bl">
    <?php $this->load->view('cms/article/side_block'); ?>
</div>
<div class="db_right bl">
    <?php if ($has_permit) :?>
    <div class="std_header auto_height">
        <div class="left">
            <strong><?php echo $module['title']; ?></strong>
        </div>
        <div class="right">
            <?php if ($has_privilege_new) :?>
            <button class="gray_btn" onclick="admin_cms_category.create_new()"><span>Thêm mới</span></button>
            <?php endif; ?>
        </div>
    </div>
    <div id="category_management">
        <div id="tab_store" class="tab_container">
            <ul>
                <li id="active_tab_list"><a href="#tab_list"><span>Danh sách chuyên mục</span></a></li>
                <li id="active_tab_edit"><a href="#tab_edit"><span>Thông tin chuyên mục</span></a></li>
            </ul>
            <div id="tab_list">
                <?php if (count($collection) != 0) : ?>
                <?php $this->load->view('cms/category/message'); ?>
                <form action="<?php echo site_url('admin/cms/category/index', true); ?>" method="post" id="frm_category_gridview">
                    <div class="block">
                        <table class="gridview" width="100%" cellpadding="0" cellspacing="0" border="0">
                            <thead>
                            <tr>
                                <td><input id="check_all" type="checkbox" onclick="btn_util.check_all(this.checked, '.chk_id')" /></td>
                                <td><b>ID</b></td>
                                <td><b>Tên</b></td>
                                <td><b>Kích hoạt</b></td>
                                <td><b>Mô tả</b></td>
                                <td><b>Thao tác</b></td>
                            </tr>
                            </thead>
                            <tbody>
                                <?php foreach ($collection as $category) : ?>
                            <tr>
                                <input type="hidden" value="" class="edit_url" />
                                <td width="30px" valign="top">
                                    <input class="chk_id" type="checkbox" name="selected[]" value="<?php echo $category->id; ?>" />
                                </td>
                                <td width="30px" valign="top">
                                    <?php echo $category->id; ?>
                                </td>
                                <td valign="top">
                                    <strong><a <?php if ($has_privilege_view) :?>class="ajax_link"<?php endif; ?> data="{id:<?php echo $category->id; ?>}" selector="#tab_edit" item="#active_tab_edit a" <?php if ($has_privilege_view) :?>href="<?php echo site_url('admin/cms/category/ajax_edit/id/' . $category->id, true); ?>"<?php endif; ?>><?php echo $category->name; ?></a></strong>
                                </td>
                                <td valign="top">
                                    <?php if ($category->is_active == 1) :?>
                                    <a class="icon icon_active"></a>
                                    <?php else :?>
                                    <a class="icon icon_deactive"></a>
                                    <?php endif; ?>
                                </td>
                                <td valign="top">
                                    <?php echo empty($category->description) ? '<span class="empty">Trống</span>' : $category->description; ?>
                                </td>
                                <td valign="top">
                                    <p>
                                        <?php if ($has_privilege_view) :?>
                                        <a class="icon icon_edit ajax_link" data="{id:<?php echo $category->id; ?>}" selector="#tab_edit" item="#active_tab_edit a" href="<?php echo site_url('admin/cms/category/ajax_edit/id/' . $category->id, true); ?>"></a>
                                        <?php endif; ?>
                                        <?php if ($has_privilege_delete) :?>
                                        <a class="icon icon_delete" href="<?php echo site_url('admin/cms/category/delete/id/' . $category->id, true); ?>" onclick="return confirm('Bạn muốn xóa chuyên mục này?')"></a>
                                        <?php endif; ?>
                                    </p>
                                </td>
                            </tr>
                                <?php endforeach; ?>
                            </tbody>
                            <tfoot>

                            </tfoot>
                        </table>
                    </div>
                </form>
                <?php else : ?>
                <div class="error_message corner">Không có chuyên mục nào trong hệ thống gian hàng</div>
                <?php endif; ?>
            </div>
            <div id="tab_edit">
                <form id="frm_category_edit" method="POST" action="<?php echo $save_action; ?>">
                    <div class="clearfix auto_height mb_10">
                        <button class="gray_btn active_item" type="button" item="#active_tab_list a"><span>Về danh sách</span></button>
                        <button class="gray_btn" type="submit"><span>Lưu lại</span></button>
                        <button class="gray_btn" type="reset"><span>Nhập lại</span></button>
                    </div>
                    <div class="form_block">
                        <div class="block_header">
                            Thông tin căn bản
                        </div>
                        <div class="block_content">
                            <table cellpadding="0px" cellspacing="0px">
                                <tr>
                                    <td class="frm_label">Tên chuyên mục(*)</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required" name="data[name]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Bí danh(*)</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input" name="data[alias]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Chọn chuyên mục cha(*)</td>
                                    <td class="frm_field">
                                        <select class="std_input" name="data[parent_id]">
                                            <option value="0">--Là chuyên mục gốc--</option>
                                            <?php foreach ($collection as $category) :?>
                                            <option value="<?php echo $category->id; ?>"><?php echo $category->name; ?></option>
                                            <?php endforeach; ?>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Thứ tự(*)</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required" name="data[sort_order]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Số bài viết trên mỗi trang(*)</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input required" name="data[article_per_page]" value="<?php echo ARTICLE_PER_PAGE; ?>" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Loại danh mục</td>
                                    <td class="frm_field">
                                        <select style="width: 300px" id="cat_type" name="data[type]">
                                            <option value="1">Danh mục hệ thống</option>
                                            <option value="2">Danh mục liên quan</option>
                                        </select>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Kích hoạt(*)</td>
                                    <td class="frm_field">
                                        <select class="std_input" name="data[is_active]">
                                            <option value="1">Có</option>
                                            <option value="0">Không</option>
                                        </select>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="form_block">
                        <div class="block_header">
                            Thông tin SEO
                        </div>
                        <div class="block_content">
                            <table cellpadding="0px" cellspacing="0px">
                                <tr>
                                    <td class="frm_label">Tiêu đề(*)</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input" name="data[meta_title]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Từ khóa(*)</td>
                                    <td class="frm_field">
                                        <input type="text" class="std_input" name="data[meta_keywords]" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="frm_label">Mô tả(*)</td>
                                    <td class="frm_field">
                                        <textarea class="std_editor"  name="data[meta_description]"></textarea>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="clearfix auto_height">
                        <button class="gray_btn active_item" type="button" item="#active_tab_list a"><span>Về danh sách</span></button>
                        <button class="gray_btn" type="submit"><span>Lưu lại</span></button>
                        <button class="gray_btn" type="reset"><span>Nhập lại</span></button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php else :?>
        <?php $this->load->view('layouts/restricted'); ?>
    <?php endif; ?>
</div>
<div class="clearfix"></div>
<script type="text/javascript">
    $("#frm_category_edit").validate();
</script>
<script type="text/javascript" src="<?php echo BASE_URL; ?>js/admin/cms/category/function.js"></script>
<script type="text/javascript" src="<?php echo BASE_URL; ?>js/admin/cms/article/function.js"></script>